package com.ee.chat.common.service.impl;

import com.ee.chat.common.dao.ChannelEarnMapper;
import com.ee.chat.common.entity.ChannelEarn;
import com.ee.chat.common.service.IChannelEarnService;
import com.ee.chat.common.vo.ChannelVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Shane
 * @Date 2020/4/9 16:07
 */
@Service
public class ChannelEarnServiceImpl implements IChannelEarnService {
    @Resource
    ChannelEarnMapper channelEarnMapper;

    @Override
    public void updateChannelEarn(ChannelVO channel, int op) {
        if(op == 1){    //更新
            channelEarnMapper.deleteByCid(channel.getId());
        }

        //收益列表
        List<ChannelEarn> earns = new ArrayList<>();
        earns.add(new ChannelEarn(channel.getId(), "first_invite_recharge_rate", channel.getFirst_invite_recharge_rate()));
        earns.add(new ChannelEarn(channel.getId(), "first_invite_vip_rate", channel.getFirst_invite_vip_rate()));
        earns.add(new ChannelEarn(channel.getId(), "first_invite_rate", channel.getFirst_invite_rate()));
        earns.add(new ChannelEarn(channel.getId(), "second_invite_rate", channel.getSecond_invite_rate()));
        if(channel.getType() == 1){ //主播渠道
            earns.add(new ChannelEarn(channel.getId(), "second_invite_recharge_rate", channel.getSecond_invite_recharge_rate()));
            earns.add(new ChannelEarn(channel.getId(), "first_invite_user_rate", channel.getFirst_invite_user_rate()));
        }
        if(channel.getType() == 3){ //工会渠道
            earns.add(new ChannelEarn(channel.getId(), "first_invite_user_rate", channel.getFirst_invite_user_rate()));
        }
        channelEarnMapper.insertBatch(earns);
    }
}
